IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Fecha_Actual')
BEGIN
DROP table ALL_IN.Fecha_Actual

END
IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Usuario')
BEGIN
DROP table ALL_IN.Usuario

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'RolxFuncionalidad')
BEGIN
DROP table ALL_IN.RolxFuncionalidad

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Funcionalidad')
BEGIN
DROP table ALL_IN.Funcionalidad

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Rol')
BEGIN
DROP table ALL_IN.Rol

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Disponibilidad_Butaca')
BEGIN
DROP table ALL_IN.Disponibilidad_Butaca

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Disponibilidad_Kg')
BEGIN
DROP table ALL_IN.Disponibilidad_Kg

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Cancelacion')
BEGIN
DROP table ALL_IN.Cancelacion

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Viaje')
BEGIN
DROP table ALL_IN.Viaje

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Recorrido')
BEGIN
DROP table ALL_IN.Recorrido

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Puntaje')
BEGIN
DROP table ALL_IN.Puntaje

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Fuera_Servicio')
BEGIN
DROP table ALL_IN.Fuera_Servicio

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Pagos')
BEGIN
DROP table ALL_IN.Pagos

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Ciudad')
BEGIN
DROP table ALL_IN.Ciudad

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Tarjeta')
BEGIN
DROP table ALL_IN.Tarjeta

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Cuota_Disponible')
BEGIN
DROP table ALL_IN.Cuota_Disponible

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Canje')
BEGIN
DROP table ALL_IN.Canje

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Cliente')
BEGIN
DROP table ALL_IN.Cliente

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Producto')
BEGIN
DROP table ALL_IN.Producto

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Butaca')
BEGIN
DROP table ALL_IN.Butaca

END




IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Micros')
BEGIN
DROP table ALL_IN.Micros

END
IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Marca')
BEGIN
DROP table ALL_IN.Marca

END

IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'Tipo_Servicio')
BEGIN
DROP table ALL_IN.Tipo_Servicio

END


IF EXISTS ( SELECT * FROM sys.views WHERE name = 'ciudadesHabilitadas' )
DROP VIEW ALL_IN.ciudadesHabilitadas
GO 

IF EXISTS ( SELECT * FROM sys.views WHERE name = 'MicrosMarca' )
DROP VIEW ALL_IN.MicrosMarca
GO 

IF EXISTS ( SELECT * FROM sys.views WHERE name = 'viajesActivos' )
DROP VIEW ALL_IN.viajesActivos
GO 



IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'CreateTables')
DROP PROCEDURE ALL_IN.CreateTables
GO



IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'MigrarDatos')
DROP PROCEDURE ALL_IN.MigrarDatos
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ControlIntentosFallidos')
DROP PROCEDURE ALL_IN.ControlIntentosFallidos
GO


IF EXISTS (SELECT * FROM sysobjects WHERE name = 'TieneFunc' AND type = 'FN')
DROP FUNCTION ALL_IN.TieneFunc
GO
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existePatente' AND type = 'FN')
DROP FUNCTION ALL_IN.existePatente
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeViaje5' AND type = 'FN')
DROP FUNCTION ALL_IN.existeViaje5
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeViaje' AND type = 'FN')
DROP FUNCTION ALL_IN.existeViaje
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeViaje2' AND type = 'FN')
DROP FUNCTION ALL_IN.existeViaje2
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeViaje3' AND type = 'FN')
DROP FUNCTION ALL_IN.existeViaje3
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeViaje4' AND type = 'FN')
DROP FUNCTION ALL_IN.existeViaje4
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeRol' AND type = 'FN')
DROP FUNCTION ALL_IN.existeRol
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeCiudad' AND type = 'FN')
DROP FUNCTION ALL_IN.existeCiudad
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeCiudadHabilitada' AND type = 'FN')
DROP FUNCTION ALL_IN.existeCiudadHabilitada
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeViajeMasAntiguo' AND type = 'FN')
DROP FUNCTION ALL_IN.existeViajeMasAntiguo
GO


IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeCliente' AND type = 'FN')
DROP FUNCTION ALL_IN.existeCliente
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeViajesActivos' AND type = 'FN')
DROP FUNCTION ALL_IN.existeViajesActivos
GO


IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeMarca' AND type = 'FN')
DROP FUNCTION ALL_IN.existeMarca
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeRecorrido' AND type = 'FN')
DROP FUNCTION ALL_IN.existeRecorrido
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'EsMicroReemplazable' AND type = 'FN')
DROP FUNCTION ALL_IN.EsMicroReemplazable
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'EsMicroReemplazable2' AND type = 'FN')
DROP FUNCTION ALL_IN.EsMicroReemplazable2
GO


IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'cambiarCiudad')
DROP PROCEDURE ALL_IN.cambiarCiudad
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'BajaCiudad')
DROP PROCEDURE ALL_IN.BajaCiudad
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'HabilitarCiudad')
DROP PROCEDURE ALL_IN.HabilitarCiudad
GO

IF EXISTS ( SELECT * FROM sys.views WHERE name = 'PuntajesHastalaFecha' )
DROP VIEW ALL_IN.PuntajesHastalaFecha
GO

IF EXISTS ( SELECT * FROM sys.views WHERE name = 'PuntajesyRecorridos' )
DROP VIEW ALL_IN.PuntajesyRecorridos
GO

IF EXISTS ( SELECT * FROM sys.views WHERE name = 'CanjeyProducto' )
DROP VIEW ALL_IN.CanjeyProducto
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'EditarCanjes')
DROP PROCEDURE ALL_IN.EditarCanjes
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'EditarProducto')
DROP PROCEDURE ALL_IN.EditarProducto
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'EditarPuntajes')
DROP PROCEDURE ALL_IN.EditarPuntajes
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'AcreditarPuntos')
DROP PROCEDURE ALL_IN.AcreditarPuntos
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'altaButacasMicro')
DROP PROCEDURE ALL_IN.altaButacasMicro
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'dameTopes')
DROP PROCEDURE ALL_IN.dameTopes
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'BorrarViajes')
DROP PROCEDURE ALL_IN.BorrarViajes
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'BorrarViajes2')
DROP PROCEDURE ALL_IN.BorrarViajes2
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'cancelarPasajes')
DROP PROCEDURE ALL_IN.cancelarPasajes
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'cancelarEncomiendas')
DROP PROCEDURE ALL_IN.cancelarEncomiendas
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'cancelaPaquete')
DROP PROCEDURE ALL_IN.cancelaPaquete
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'cancelaPasaje')
DROP PROCEDURE ALL_IN.cancelaPasaje
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'RestarPuntajes')
DROP PROCEDURE ALL_IN.RestarPuntajes
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ViajesDisponibles')
DROP PROCEDURE ALL_IN.ViajesDisponibles
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ViajesDisponibles2')
DROP PROCEDURE ALL_IN.ViajesDisponibles2
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ButacasDisponibles')
DROP PROCEDURE ALL_IN.ButacasDisponibles
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'MicrosReemplazables')
DROP PROCEDURE ALL_IN.MicrosReemplazables
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'EsMicroReemplazable')
DROP PROCEDURE ALL_IN.EsMicroReemplazable
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'agregarButacas')
DROP PROCEDURE ALL_IN.agregarButacas
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'MicrosReemplazablesServicio')
DROP PROCEDURE ALL_IN.MicrosReemplazablesServicio
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'EsMicroReemplazableServicio')
DROP PROCEDURE ALL_IN.EsMicroReemplazableServicio
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'actualizarCliente')
DROP PROCEDURE ALL_IN.actualizarCliente
GO


	IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.TABLES
					WHERE TABLE_SCHEMA = 'ALL_IN'
					AND TABLE_NAME = 'tempTable')
	BEGIN
		DROP table ALL_IN.tempTable

	END
	
	IF EXISTS (SELECT *
					FROM INFORMATION_SCHEMA.SCHEMATA
					WHERE SCHEMA_NAME = 'ALL_IN')
					
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'VerificaFecha' AND type = 'FN')
DROP FUNCTION ALL_IN.VerificaFecha
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'clienteenviaje' AND type = 'FN')
DROP FUNCTION ALL_IN.clienteenviaje
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeTarjeta' AND type = 'FN')
DROP FUNCTION ALL_IN.existeTarjeta
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'existeTarjeta2' AND type = 'FN')
DROP FUNCTION ALL_IN.existeTarjeta2
GO


IF EXISTS (SELECT * FROM sysobjects WHERE name = 'trg_EliminarViaje' AND type = 'TR' )
DROP TRIGGER ALL_IN.trg_EliminarViaje
GO


IF EXISTS (SELECT * FROM sysobjects WHERE name = 'trg_InsertCancelacion' AND type = 'TR' )
DROP TRIGGER ALL_IN.trg_InsertCancelacion
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'trg_AsignarPuntajes' AND type = 'TR' )
DROP TRIGGER ALL_IN.trg_AsignarPuntajes
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'trg_AsignarPuntajes2' AND type = 'TR' )
DROP TRIGGER ALL_IN.trg_AsignarPuntajes2
GO



IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'DestinosConMasPasajesComprados')
DROP PROCEDURE ALL_IN.DestinosConMasPasajesComprados
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'DestinosMicrosMasVacios')
DROP PROCEDURE ALL_IN.DestinosMicrosMasVacios
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'pasajesCancelados')
DROP PROCEDURE ALL_IN.pasajesCancelados
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'mayorCantidadDiasFueraDeServicio')
DROP PROCEDURE ALL_IN.mayorCantidadDiasFueraDeServicio
GO

					
BEGIN
DROP SCHEMA ALL_IN

END

